// 聊天会话
export interface ChatSession {
  id: string;
  userId: string;
  title: string;
  personaId?: string;
  personaName?: string;
  personaAvatar?: string;
  lastMessage?: string;
  lastMessageAt?: string;
  messageCount: number;
  unreadCount?: number;
  isArchived: boolean;
  isFavorite: boolean;
  tags: string[];
  metadata?: Record<string, any>;
  createdAt: string;
  updatedAt: string;
}

// 聊天消息
export interface ChatMessage {
  id: string;
  sessionId: string;
  content: string;
  type: "text" | "image" | "file" | "audio" | "video" | "system";
  role: "user" | "assistant" | "system";
  personaId?: string;
  parentId?: string; // 用于回复消息
  attachments?: MessageAttachment[];
  metadata?: MessageMetadata;
  status: "sending" | "sent" | "delivered" | "read" | "failed" | "streaming";
  rating?: "like" | "dislike";
  isFavorite?: boolean;
  isEdited?: boolean;
  editHistory?: MessageEdit[];
  timestamp: Date;
  createdAt?: string;
  updatedAt?: string;
}

// 消息附件
export interface MessageAttachment {
  id: string;
  name: string;
  type: "image" | "file" | "audio" | "video";
  url: string;
  size: number;
  mimeType: string;
  thumbnail?: string;
  duration?: number; // 音频/视频时长
  dimensions?: {
    width: number;
    height: number;
  };
}

// 消息元数据
export interface MessageMetadata {
  tokensUsed?: number;
  responseTime?: number;
  model?: string;
  temperature?: number;
  maxTokens?: number;
  reasoning?: string;
  sources?: Array<{
    title: string;
    url: string;
    snippet: string;
  }>;
  emotions?: Array<{
    emotion: string;
    confidence: number;
  }>;
  intent?: {
    category: string;
    confidence: number;
  };
  language?: string;
  sentiment?: {
    score: number;
    label: "positive" | "negative" | "neutral";
  };
}

// 消息编辑历史
export interface MessageEdit {
  id: string;
  content: string;
  editedAt: string;
  reason?: string;
}

// 发送消息请求
export interface SendMessageRequest {
  sessionId: string;
  content: string;
  type: "text" | "image" | "file";
  personaId?: string;
  parentId?: string;
  attachments?: File[];
  metadata?: Record<string, any>;
}

// 人格定义
export interface Persona {
  id: string;
  name: string;
  description: string;
  avatar?: string;
  category: string;
  tags: string[];
  systemPrompt: string;
  isActive: boolean;
  isDefault: boolean;
  isPublic: boolean;
  isOfficial: boolean;
  createdBy?: string;
  createdByName?: string;
  config: PersonaConfig;
  stats: PersonaStats;
  rating: {
    average: number;
    count: number;
  };
  createdAt: string;
  updatedAt: string;
}

// 人格配置
export interface PersonaConfig {
  model?: string;
  temperature?: number;
  maxTokens?: number;
  topP?: number;
  frequencyPenalty?: number;
  presencePenalty?: number;
  stopSequences?: string[];
  responseFormat?: "text" | "json" | "markdown";
  enableMemory?: boolean;
  memorySize?: number;
  enableTools?: boolean;
  availableTools?: string[];
  personality?: {
    traits: string[];
    mood: string;
    style: string;
    formality: "casual" | "formal" | "friendly" | "professional";
  };
  knowledge?: {
    domains: string[];
    specialties: string[];
    limitations: string[];
  };
  behavior?: {
    responseLength: "short" | "medium" | "long" | "adaptive";
    creativity: number; // 0-1
    helpfulness: number; // 0-1
    empathy: number; // 0-1
  };
}

// 人格统计信息
export interface PersonaStats {
  totalSessions: number;
  totalMessages: number;
  averageRating: number;
  totalRatings: number;
  favoriteCount: number;
  usageGrowth: number;
  popularityRank: number;
  lastUsed?: string;
  responseTime: {
    average: number;
    median: number;
  };
  satisfaction: {
    score: number;
    trend: "up" | "down" | "stable";
  };
}

// 人格评价
export interface PersonaRating {
  id: string;
  userId: string;
  username: string;
  userAvatar?: string;
  personaId: string;
  rating: number; // 1-5
  comment?: string;
  helpful?: boolean;
  createdAt: string;
  updatedAt: string;
}

// 聊天模板
export interface ChatTemplate {
  id: string;
  name: string;
  description: string;
  category: string;
  personaId: string;
  personaName: string;
  initialMessages: Array<{
    role: "user" | "assistant";
    content: string;
  }>;
  tags: string[];
  difficulty: "beginner" | "intermediate" | "advanced";
  estimatedDuration: number; // 分钟
  popularity: number;
  createdBy?: string;
  isOfficial: boolean;
  createdAt: string;
}

// 消息搜索结果
export interface MessageSearchResult {
  message: ChatMessage;
  session: {
    id: string;
    title: string;
    personaName?: string;
  };
  highlights: string[];
  relevanceScore: number;
}

// 聊天统计
export interface ChatStats {
  totalSessions: number;
  totalMessages: number;
  totalTokens: number;
  averageSessionLength: number;
  mostUsedPersona: {
    id: string;
    name: string;
    usage: number;
  };
  dailyStats: Array<{
    date: string;
    sessions: number;
    messages: number;
    tokens: number;
  }>;
  topCategories: Array<{
    category: string;
    count: number;
    percentage: number;
  }>;
  responseTimeStats: {
    average: number;
    median: number;
    p95: number;
  };
}

// 会话分享
export interface SessionShare {
  id: string;
  sessionId: string;
  shareId: string;
  shareUrl: string;
  title: string;
  description?: string;
  includeSystemMessages: boolean;
  isPublic: boolean;
  password?: string;
  expiresAt?: string;
  viewCount: number;
  createdBy: string;
  createdAt: string;
}

// 实时聊天状态
export interface ChatStatus {
  isOnline: boolean;
  isTyping: boolean;
  lastSeen?: string;
  currentPersona?: {
    id: string;
    name: string;
    avatar?: string;
  };
}

// WebSocket 消息类型
export interface WebSocketMessage {
  type:
    | "ping"
    | "pong"
    | "chat"
    | "typing"
    | "message_chunk"
    | "message_complete"
    | "error"
    | "status";
  data?: any;
  timestamp?: number;
  messageId?: string;
}

// 聊天事件
export interface ChatEvent {
  type:
    | "message_sent"
    | "message_received"
    | "session_created"
    | "session_updated"
    | "persona_switched"
    | "typing_start"
    | "typing_stop";
  sessionId: string;
  data: any;
  timestamp: string;
}

// 消息流
export interface MessageStream {
  id: string;
  sessionId: string;
  content: string;
  isComplete: boolean;
  error?: string;
  metadata?: MessageMetadata;
}

// 聊天设置
export interface ChatSettings {
  autoSave: boolean;
  showTypingIndicator: boolean;
  enableMarkdown: boolean;
  enableCodeHighlight: boolean;
  enableLatex: boolean;
  messageGrouping: boolean;
  timestampFormat: "12h" | "24h" | "relative";
  bubbleStyle: "classic" | "modern" | "minimal";
  fontSize: "small" | "medium" | "large";
  lineHeight: "compact" | "normal" | "relaxed";
  maxMessageLength: number;
  enableSounds: boolean;
  enableAnimations: boolean;
  compactMode: boolean;
}

// 聊天快捷操作
export interface ChatShortcut {
  id: string;
  name: string;
  description: string;
  trigger: string;
  content: string;
  category: string;
  isGlobal: boolean;
  personaId?: string;
  createdBy: string;
  usageCount: number;
  createdAt: string;
}

// 聊天主题
export interface ChatTheme {
  id: string;
  name: string;
  description: string;
  colors: {
    primary: string;
    secondary: string;
    background: string;
    surface: string;
    userBubble: string;
    assistantBubble: string;
    text: string;
    textSecondary: string;
    border: string;
    accent: string;
  };
  fonts: {
    primary: string;
    secondary: string;
    code: string;
  };
  borderRadius: number;
  shadows: boolean;
  animations: boolean;
  isDefault: boolean;
  isPremium: boolean;
  createdAt: string;
}

// 分页响应
export interface PageResponse<T> {
  content: T[];
  totalElements: number;
  totalPages: number;
  size: number;
  number: number;
  first: boolean;
  last: boolean;
  empty: boolean;
}
